package cn.lliiooll.ippzonetoolbox.utils;

import android.os.Build;
import android.os.Environment;
import cn.lliiooll.ippzonetoolbox.ui.activities.nowm.NowmActivity;

import java.io.File;

public class FileUtils {
    public static File getFile(String url) {
        File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsoluteFile() + "/pipitoolbox/");
        File f = new File(dir, url.substring(url.length() - 30) + ".mp4");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {// 大于等于安卓10
            f = new File(NowmActivity.getInstance().getFilesDir(), url.substring(url.length() - 30) + ".mp4");
            dir = NowmActivity.getInstance().getFilesDir();
        }
        if (f.exists()) {
            f = new File(dir, url.substring(url.length() - 30) + "-" + StringUtils.random(8) + ".mp4");
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {// 大于等于安卓10
                f = new File(NowmActivity.getInstance().getFilesDir(), url.substring(url.length() - 30) + "-" + StringUtils.random(8) + ".mp4");
                dir = NowmActivity.getInstance().getFilesDir();
            }
        }
        return f;
    }
}
